$(function() { $("#tabs").tabs();  });
  
$(document).ready(function() { 
    
    hs.graphicsDir = url_base+'app/admin/view/temp/default/layout/css/highslide/graphics/';
    hs.align = 'center';
    hs.closeText = '<img border="0" src="'+url_base+'app/admin/view/temp/default/layout/css/highslide/graphics/close_X.png" />';
    hs.creditsText = 'this.a.title';
    hs.outlineType = 'rounded-white';
    hs.showCredits = false;
    hs.wrapperClassName = 'draggable-header';
    hs.cacheAjax = false;
    hs.dimmingOpacity = 0.7;
    hs.onDimmerClick = function() { return false;}
    
     
    $('#btn-submit').click(function() {  
    
      var hasError = false;
      var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    
      var emailaddressVal = $("#Email").val();
      if(emailaddressVal == '') {
          $(".error").show().text(_['error_emal_empty']);
          hasError = true;
      }
    
      else if(!emailReg.test(emailaddressVal)) {
          $(".error").show().text(_['error_emal_no_format']);
          hasError = true;
      }
    
      if(hasError == true) { return false; }
    
    });
    
    $('input:checkbox[name="delId[]"]').click(function() { 
    
    if( $(this).attr("checked")== "checked"){
        
        $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
        
    }else{
        
        if(getValCb().length>0)
        {               
            $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
        }else{
            $('.but_tool').removeClass('but_login').addClass('butx').attr("disabled",true);   
        }
        
        
    }
    
    
    
    });
 });

function move_div(ID,NO)
{ 
    $( "#div"+ID ).sortable({
        stop: function(event, ui) { 
    		str_id = set_order("div"+ID);
    		setOrderAjax(str_id,'order');
            $( "#div"+ID ).sortable("destroy");
        }
    }); 
          
}
   
 
function set_order(ID)
{    
    var str = '';
	var len = $("#"+ID+">div").length;
    if(len>0)
    {
        str += $("#"+ID+">div:eq(0) input").val();
        $("#"+ID+">div:eq(0) span.order-val:eq(0)").text(1);
        for(var i=1; i<len; i++)
        {
           str = str + ',' + $("#"+ID+">div:eq("+i+") input").val(); 
           $("#"+ID+">div:eq("+i+") span.order-val:eq(0)").text(i+1);
        }
    }
    
    return str;
}
function showHide(ID,e,indent)
{	
	if(document.getElementById('div'+ID).style.display=='none')
    {		              
        $('#div'+ID).show();
        $(e).removeClass('ui-icon-plus');
        $(e).addClass('ui-icon-minus');
               
	}else{
	   
		$('#div'+ID).hide();
        $(e).removeClass('ui-icon-minus');
        $(e).addClass('ui-icon-plus');
	}	
} 
function checkAll()
{
    if(getValCb().length>0){
        
        $('.but_tool').removeClass('but_login').addClass('butx').attr("disabled",true);
        $('input:checkbox[name="all"]').removeAttr("checked");
		$('input:checkbox[name="delId[]"]').removeAttr("checked");
        
	}else{
	    
        $('.but_tool').removeClass('butx').addClass('but_login').attr("disabled",false);
	    $('input:checkbox[name="all"]').attr("checked","checked");
		$('input:checkbox[name="delId[]"]').attr("checked","checked");
    }
	
}

function getValCb()
{
	var delId = [];
	$('input:checkbox[name="delId[]"]:checked')
	.each( function(index) { 
		delId.push($(this).val());
	});
	
	return delId;
}

function del_pic(path_pic,CatID)
{
    var url = _seokey[0]+"/ajax/delpic/"+CatID+"/"+path_pic+"/";
    $.ajax({
        type    : "GET",
        url     : url_base+url,
        cache   : false,
        dataType: "html",
        success: function(DataHtml)
        {
            document.getElementById('id_img').src=url_base+'upload/noimg.png';
            $('#id_img_but').hide();
            $('#id_img_input').show();
        }

    });

}

function setOrderAjax(ID,act)
{
    var url = _seokey[0]+"/ajax/"+act+"/"+ID+"/";
    $.ajax({ 
        type    : "GET",
        url     : url_base+url, 
        cache   : false

     });
}

function processChecked(active)
{
    var StrID = getValCb();
	switch (active)
	{
		case 'show':
			var strData = _seokey[0]+"/ajax/"+active+"/"+StrID;
			var sms = _['showx'];
			var smsError=_['error_show'];
			var errorNotOK = _['error_ok_show'];
            var status = _['show'];
            var classx = 're';
        break;
		
		case 'hide':
			var strData = _seokey[0]+"/ajax/"+active+"/"+StrID;
			var sms =  _['hidex'];
			var smsError=_['error_hide'];
			var errorNotOK = _['error_ok_hide'];
            var status = _['hide'];
            var classx = 'add';
        break;
		
		case 'del':
			var strData = _seokey[0]+"/ajax/"+active+"/"+StrID;
			var sms =  _['delx'];
			var smsError=_['error_del'];
			var errorNotOK = _['error_ok_del'];
            var status = _['del'];
            var classx = 'add';
		break;
        
        case 'delete':
			var strData = _seokey[0]+"/ajax/"+active+"/"+StrID;
			var sms =  _['delete'];
			var smsError=_['error_delete'];
			var errorNotOK = _['error_ok_delete'];
            var deletex = 'ok';
		break;
        
	}
	
	if(StrID!=""){
		var smsCheck = confirm(sms);
		if(smsCheck==true){
			$.ajax({ 
			   type: "POST", 
			   url: url_base+""+strData, 
			   cache: false,
			   dataType: "html",
			   success: function(DataHtml){ 
			   	 if(DataHtml=='ok')
                 {
				 	for(x in StrID)
                    {
                        if(StrID[x]!=2){
                            if(deletex)
                            {
                                $('.tr'+StrID[x]).remove();                                
                            }
                            else{
                             
                                $('.status'+StrID[x]).text(status);
                                if(classx=='add'){
                                    $('.tr'+StrID[x]).addClass('cell_groupitem_ex');
                                }else{
                                    $('.tr'+StrID[x]).removeClass('cell_groupitem_ex');
                                }
                                
                            }
                        }
                        
                    }
				 }
                 else{
                    alert(errorNotOK);                   
                    
				 }
				 
			   } 
			});
		}
	
	}else{
		alert(smsError);
	
	}
}



function create_seo(lang)
{ 
   $name = $('#CatName_'+lang).val();
   $seokey = getLinkSeo($name);
   $('#SeoKey_'+lang).val($seokey);
   $('#Title_'+lang).val($name);
   $('#Desc_'+lang).val($name);
   $('#Keyword_'+lang).val($name);
   $('#TitleH1_'+lang).val($name);
   $('#TitleH2_'+lang).val($name);
   $('#DescF_'+lang).val($name);    
}

function reloadImg(id) {
    var obj = document.getElementById(id);
    var src = obj.src;
    obj.src = src;
    return false;
}





